package cc.vicp.djx314.starfood.web.count;

import java.util.Date;
import java.util.List;
import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;

import cc.vicp.djx314.starfood.service.count.CountService;

@Controller
public class GetSalesByWeekController {
	public static final Logger logger = LoggerFactory.getLogger(GetSalesByWeekController.class);

	@Autowired
	private CountService countService;

	@RequestMapping(value = "/manager/sales/week", method = RequestMethod.GET)
	public ModelAndView getSalesByWeek() {
		ModelAndView model = new ModelAndView("jsontournamenttemplate");
		boolean success = false;
		List<Map<String, Double>> sales = null;
		try {
			Date today = new Date();
			sales = countService.getSalesLastWeek(today);
			success = true;
		} catch (Exception e) {
			logger.info("获取上周销量出错", e);
		}
		model.addObject("sales", sales);
		model.addObject("success", success);
		return model;
	}
}